package org.example.view;

import org.example.dao.FunctionsDao;
import org.example.dao.PublishDao;
import org.example.dao.UsersDao;

import java.util.Scanner;

// 查询 文章
public class QueryArticleView {

    public void queryArticle(int id) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int i=0;
        while (true){
            show();
            System.out.println("请输入操作数：");
            switch (scanner.nextInt()) {
                case 1:
                    System.out.println("请输入查询的作者名称：");
                    String userName1 = scanner.next();
                    i=new PagingView().showPaging(1,8,new PublishDao().listPublishByUserCount(userName1),2,userName1,0,null,null,0);
                    if(i==0){
                        return;
                    }
                    new MeneView().functions(id, i, new UsersDao().getUserName(id),new FunctionsDao().likePublish(id, i),-1);
                    break;
                case 2:
                    System.out.println("请输入查询的标签：");
                    System.out.println("\t1. java  \t2. 大数据");
                    System.out.println("\t3. 算法   \t0.其他");
                    int tags = scanner.nextInt();
                    i=new PagingView().showPaging(1,8,new PublishDao().listPublishByTagsCount(tags),3,"",tags,null,null,0);
                    if(i==0){
                        return;
                    }
                    new MeneView().functions(id, i, new UsersDao().getUserName(id),new FunctionsDao().likePublish(id, i),-1);
                    break;
                case 3:
                    System.out.println("请输入要查找的标题: ");
                    String title = scanner.next();
                    i=new PagingView().showPaging(1,8,new PublishDao().listPublishByTitleCount(title),4,"",0,title,null,0);
                    if(i==0){
                        return;
                    }
                    new MeneView().functions(id, i, new UsersDao().getUserName(id),new FunctionsDao().likePublish(id, i),-1);
                    break;
                case 4:
                    System.out.println("请输入要查询的概要：");
                    String outline = scanner.next();
                    i=new PagingView().showPaging(1,8,new PublishDao().listPublishByOutlineCount(outline),5,"",0,null,outline,0);
                    if(i==0){
                        return;
                    }
                    new MeneView().functions(id, i, new UsersDao().getUserName(id),new FunctionsDao().likePublish(id, i),-1);
                    break;
                case 0:
                    return;
                default:
                    System.out.println("输入错误,请重新输入!");
                    break;
            }
        }


    }

    public void show() {
        System.out.println("\n1.查询作者");
        System.out.println("2.查询标签");
        System.out.println("3.查询标题");
        System.out.println("4.查询概要");
        System.out.println("0.返回");
    }

}
